//
//  AddressIsDefaultCell.m
//  WeiYiMei
//
//  Created by iMac on 2019/4/17.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "AddressIsDefaultCell.h"

@interface AddressIsDefaultCell ()

@property (nonatomic, strong) UILabel *titleLab;

@property (nonatomic, strong) UISwitch *defaultOnOff;

@end

@implementation AddressIsDefaultCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupSubViews];
    }
    return self;
}

- (void)setupSubViews
{
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.font = [UIFont systemFontOfSize:15];
    self.titleLab.textColor = kColor333333;
    self.titleLab.textAlignment = NSTextAlignmentLeft;
    self.titleLab.text = @"设为默认地址";
    [self addSubview:self.titleLab];
    
    self.defaultOnOff = [[UISwitch alloc] init];
    [self addSubview:self.defaultOnOff];
    
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(16);
        make.centerY.equalTo(self);
    }];
    
    [self.defaultOnOff mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-16);
        make.centerY.equalTo(self);
    }];
    
    [self.defaultOnOff addTarget:self action:@selector(onOffAction:) forControlEvents:UIControlEventValueChanged];
}

- (void)setIsDefault:(BOOL)isDefault
{
    _isDefault = isDefault;
    self.defaultOnOff.on = isDefault;
}

- (void)onOffAction:(UISwitch *)sender
{
    if (self.defaultHandler) {
        self.defaultHandler(sender.isOn);
    }
}

@end
